package com.lanou.controller;

import com.lanou.entity.Article;
import com.lanou.service.ArticleService;
import com.lanou.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName ArticleController
 * @Description TODO
 * @Author lizhenjiang
 * @Date 2025年08月13日 20:14
 * @Version 1.0
 */
@RestController
@RequestMapping("article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @GetMapping("{id}")
    public R getArticleById(@PathVariable Integer id) {
        return R.ok(articleService.selectArticleById(id));
    }

    @GetMapping("byPage")
    public R getArticleByPage(Article article,
                              @RequestParam(value = "pageNum",required = false) Integer pageNum,
                              @RequestParam(value = "pageSize",required = false) Integer pageSize
    ) {
        return R.ok(articleService.selectArticleList(article,pageNum,pageSize));
    }

    @PutMapping()
    public R updateArticleById(@RequestParam(value = "id") Integer id,@RequestParam(value = "status") String status,
                               @RequestParam(value = "userId") Integer userId) {
        return R.ok(articleService.updateArticle(id,status,userId));
    }
}
